package br.com.reference.gui;

import br.com.reference.gui.screens.StartScreen;
import java.awt.Graphics2D;
import java.awt.SplashScreen;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

/**
 * Classe principal, que invoca o screensplash e a janela principal.
 *
 * @author Rossini Saboya (rossini.neto@gmail.com)
 * @since 19/04/2010
 */
public class Main {

    /**
     * Chamada inicial do projeto.
     *
     * @param args
     */
    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                preconfigure();
                startSplashScreen();
                new StartScreen();
            }
        });
    }

    public static void preconfigure() {
        try {
            UIManager.setLookAndFeel(
                    UIManager.getCrossPlatformLookAndFeelClassName());
        } catch (Exception e) {
            try {
                // TODO: ROssini - Logar
                UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
            } catch (ClassNotFoundException ex) {
                // TODO: ROssini - Logar
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                // TODO: ROssini - Logar
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                // TODO: ROssini - Logar
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            } catch (UnsupportedLookAndFeelException ex) {
                // TODO: ROssini - Logar
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    public static void startSplashScreen() {
        final SplashScreen splash = SplashScreen.getSplashScreen();
        if (splash == null) {
            // TODO: ROssini - Logar
            return;
        }
        Graphics2D g = splash.createGraphics();
        if (g == null) {
            // TODO: ROssini - Logar
            return;
        }
        for (int i = 0; i < 100; i++) {
            try {
                Thread.sleep(90);
            } catch (InterruptedException ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        splash.close();
    }
}
